﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Core
{
    /// <summary>
    /// Argument
    /// </summary>
    public class Argument
    {
        /// <summary>
        /// Argument name
        /// </summary>
        private String _Name;
        public String Name
        {
            get { return _Name; }
        }

        /// <summary>
        /// Argument data type
        /// </summary>
        private DataType _Type;
        public DataType Type
        {
            get { return _Type; }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="input"></param>
        public Argument(String input)
        {
            // sample: myVar:N

            // (?<name>\S+)             : argument name
            // (?<datatype>\S+)         : argument datatype
            String pattern = @"(?<name>\S+) : (?<datatype>\S+)";

            // is match ?
            if (Regex.IsMatch(input, pattern, RegexOptions.IgnorePatternWhitespace))
            {
                Match match = Regex.Match(input, pattern, RegexOptions.IgnorePatternWhitespace);

                // set value for name and datatype
                _Name = match.Groups["name"].Value;
                _Type = new DataType(match.Groups["datatype"].Value);
            }
            else
            {
                throw new Exception("Argument ERROR!!!");
            }
        }
    }
}
